<?php

// Error if we don't have a Project ID and Crudset ID
//Incluce DB connect 
include_once "quickcrud_connect.php";
//include_once "commonctls.php";
include "CF_mysql_com.php";
include_once "CF_all_com.php";
include_once "qc_functions.php";
include_once "dbinfo/dbinfo.php";

if (!isset($_REQUEST['project_id']) ){
	print 'Please select or create a project first';
exit;
}

$project_id = $_REQUEST['project_id'];
// get all tables for db

	$dbServer = lookup_value('project_server', 'projects', " project_id = $project_id ");
	$dbUsername = lookup_value('project_login', 'projects', " project_id = $project_id ");
	$dbDatabase = lookup_value('project_db', 'projects', " project_id = $project_id ");
	$dbPassword = lookup_value('project_pass', 'projects', " project_id = $project_id ");

	$arr_tableList = getTableList($dbDatabase,$dbUsername,$dbPassword,$dbServer);
	
// Back to this connection
include "quickcrud_connect.php";
	
foreach($arr_tableList as $tablename){

	get_table_vars($tablename, $project_id);	
	
// for each table, setup crudset
	$table_id = lookup_value('tablesource_id', 'tablesources', " project_id = $project_id AND table_alias = '$tablename' ");
	fill_set_from_table($table_id, $project_id, 0, 'inline_edit');

}	
	

//return
$result = "Table: $table_name Variables added and set created";
$result = urlencode($result);
$header_text = "Location: leftmenu.php?project_id=$project_id&result=$result";
header($header_text); /* Redirect browser */

?>